export class Pubsub {
    _watcher = null;

    constructor() {
        this.watcher = new Map();

    }

    get watcher() {
        return this._watcher;
    }

    set watcher(value) {
        this._watcher = value;
    }


    subscriber(event, callback) {
        if (this.watcher.has(event)) {
            let watcherArr = this.watcher.get(event);
            watcherArr.push(callback);
            this.watcher.set(event, watcherArr);
        } else {
            let watcherArr = []
            watcherArr.push(callback);
            this.watcher.set(event, watcherArr);
        }
    }

    pubsub(event, value) {
        if (this.watcher.has(event)) {
            let pubsubArr = this.watcher.get(event);
            for (const callback of pubsubArr) {
                callback(value)
            }
        }


    }
}